package com.quarkus.weather.service;

import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import javax.enterprise.context.ApplicationScoped;

@ApplicationScoped
public class WeatherService {

    public String getCityWeather(String city) throws Exception {
        String url = "http://wthrcdn.etouch.cn/weather_mini?city=" + city;
        OkHttpClient okHttpClient = new OkHttpClient();
        final Request request = new Request.Builder()
                .url(url)
                .build();
        final Call call = okHttpClient.newCall(request);
        Response response = call.execute();
        String ret =  response.body().string();
        System.out.println("查询天气数据：" + ret);
        return ret;
    }

    public String getCityWeather() throws Exception {
        return getCityWeather("南京");
    }

    public String hello() {
        return "Hello!";
    }
}
